package cs;

import java.io.*;
import java.net.Socket;
import java.util.*;

public class ObjectThread extends Thread {
    private Socket s;
    public ObjectThread(Socket s){
        this.s=s;
    }
    private static Map<String,String> map=new HashMap<>();
    static{
        map.put("clsname","java68");
        map.put("最帅","张翔");
        map.put("最高","刘晓静");
        map.put("最胖","杨勇");
    }
    @Override
    public void run() {
        System.out.println(s+"连接了");
        FileInputStream fin= null;
        try {
            map.put("你的ip",s.getInetAddress().toString());
            //InputStream in=s.getInputStream();
            OutputStream out = s.getOutputStream();
            ObjectOutputStream oout=new ObjectOutputStream(out);
            oout.writeObject(map);
            oout.reset();
            oout.flush();
            System.out.println("对象发送给"+s+"成功");
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(s!=null&&!s.isClosed()) {
                try {
                    s.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
